// 合并 config
function getConfig(target, obj) {
  for (const [k, v] of Object.entries(obj)) {
    if (!target[k]) target[k] = {};
      switch (v.constructor.name) {
      case 'Object':
        target[k] = getConfig(target[k], v)
        break;
      case 'Array':
        target[k] = Array.from(new Set([...target[k],...v]))
      default:
        target[k] = v
    }
  }
  return target;
}

// 配置文件, 支持当前目录创建 private.js 导出私人config, 将与该对象合并
const config = {
  // 私人配置文件路径
  private: './private',
  bot: {
    adminId: 11111111,
    groups: { "123321": false },
    name: 'rava',
    nameList: ['rava', '拉瓦'],
    ws: 'ws://0.0.0.0:10001',
    server: 'http://localhost:10000/api/v1'
  },
  plugins: {
    // "ali-ddns": {
    //   IpApi: "http://xxxx/",
    //   AccessKeyId: "xxx",
    //   AccessKeySecret: "xxx",
    //   Domain: "xxx.xxx",
    //   SubDomain: "xxx",
    //   TypeKeyWord: "AAAA"
    // }
  }
};

if (config.private) {
  let private;
  try {
    private = require(config.private);
  } catch {
    private = {};
  }
  getConfig(config, private);
}

console.log(config)

module.exports = config;